<?

class Menudinamico
{
	public $grupo;
	
	public function getMenu()
	{
		$session = "menu_" . AppBaseController::$session;
		
		$session_menu = new Zend_Session_Namespace($session);
			
		if($session_menu->menu)
		{
			return $session_menu->menu;
		}
		
		$menu = new INT002();
		
		if($this->grupo == 99)
		{
			$arrMenu = $menu->getMenuAdmin();
		}
		else
		{
			$arrMenu = $menu->getMenu();		

			$permissao = new Permissao();
		
			foreach ($arrMenu as $key => $val)
			{
				if(in_array($val["INT002_link"], $permissao->getPermissaoMenu()))
				{
					unset($arrMenu[$key]);
				}	
				
			}
		}
		
		$session_menu->menu = $arrMenu;		
		
		return $arrMenu;
	}
	
	public function getSubMenu()
	{
		$session = "menu_" . AppBaseController::$session;
		
		$session_menu = new Zend_Session_Namespace($session);
			
		if($session_menu->submenu)
		{
			return $session_menu->submenu;
		}
		
		$sub = new INT003();
		
		$permissao = new Permissao();
		
		$arrSu = $sub->getMenuSubMenu();
		
		foreach ($arrSu as $key => $val)
		{
			foreach ($permissao->subMenu as $k => $v)
			{
				$act = split("-", $v);
			
				foreach ($act as $aa)
				{
					if($val["INT002_link"] == $k && $val["INT003_link"] == $aa)
					{
						unset($arrSu[$key]);
					}
				}
		/*		if($val["INT002_link"] == $k && $val["INT003_link"] == $v)
				{
					unset($arrSu[$key]);
				}*/
				
				//echo " " . $val["INT002_link"] . " = " . " $k && " . $val["INT003_link"] . "==" . $v;
			}
		}
		
		$session_menu->submenu = $arrSu;	
		
		return $arrSu;
	}
	
	public function setGrupo($grupo)
	{
		$this->grupo = $grupo;
	}
}

?>